/*******************************************************************************
 * @project: EveryClass
 * @package: com.burns.everyclass.lunene.utils
 * @file: SystemUtils.java
 * @author: Administrator
 * @created: 2017年6月4日
 * @purpose:
 * 
 * @version: 1.0
 * 
 * Revision History at the end of file.
 * 
 * Copyright 2017 AcconSys All rights reserved.
 ******************************************************************************/

package com.burns.everyclass.lunene.utils;

import java.io.File;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

import javax.swing.filechooser.FileSystemView;

public class SystemUtils {

	public static List<File> jarFileList = new ArrayList<File>();

	public static void main(String[] args) {
		getDrivers();
	}

	public static String FormetFileSize(long fileS) {
		DecimalFormat df = new DecimalFormat("#.00");
		String fileSizeString = "";
		if (fileS < 1024) {
			fileSizeString = df.format((double) fileS) + "B";
		} else if (fileS < 1048576) {
			fileSizeString = df.format((double) fileS / 1024) + "K";
		} else if (fileS < 1073741824) {
			fileSizeString = df.format((double) fileS / 1048576) + "M";
		} else {
			fileSizeString = df.format((double) fileS / 1073741824) + "G";
		}
		return fileSizeString;
	}

	/**
	 * 获取硬盘的每个盘符
	 */
	public static File[] getDrivers() {
		// 当前文件系统类
		FileSystemView fsv = FileSystemView.getFileSystemView();
		// 列出所有windows 磁盘
		File[] fs = File.listRoots();
		// 显示磁盘卷标
		for (int i = 0; i < fs.length; i++) {
			System.out.println(fsv.getSystemDisplayName(fs[i]));
			System.out.print("总大小" + FormetFileSize(fs[i].getTotalSpace()));
			System.out.println("剩余" + FormetFileSize(fs[i].getFreeSpace()));
		}
		return fs;
	}

	public static void getFilesFromDirectory(File dirFile) {
		JarFileFilter filter = new JarFileFilter();
		File[] files = dirFile.listFiles();
		for (File file : files) {
			if (file.isDirectory()) {
				getFilesFromDirectory(file);
			} else if (filter.accept(file)) {
				jarFileList.add(file);
			}
		}
	}

	public static List<File> getJarFileList() {
		return jarFileList;
	}

	public static void setJarFileList(List<File> jarFileList) {
		SystemUtils.jarFileList = jarFileList;
	}
}

/*******************************************************************************
 * <B>Revision History</B><BR>
 * [type 'revision' and press Alt + / to insert revision block]<BR>
 * 
 * 
 * 
 * Copyright 2017 AcconSys All rights reserved.
 ******************************************************************************/